import router from '@/router'
import { nextTick } from 'vue';
import { useTitle } from '@vueuse/core'
/**
 * 加载网络css
 * @param {*} url css资源远程地址
 */
export function loadCss(url){
    const link=document.createElement('link');
    link.rel='stylesheet';
    link.href=url;
    link.crossOrigin='anonymous',
    document.getElementsByTagName('head')[0].appendChild(link);
}
/**
 * 
 * @param {*} url js资源url
 */
export function loadJs(url){
    const link=document.createElement('script')
    link.src=url;
    document.body.appendChild(link)

}
/**
 * 根据路由 meta.title 设置浏览器标题
 */
export function setTitleFormatRoute(){
    if(router.currentRoute.value.meta.title != 'string'){
        return;
    }
    nextTick(()=>{
        let webTitle='';
        if(router.currentRoute.value.meta.title.indexOf('pagesTitle.'===-1)){
            webTitle=router.currentRoute.value.meta.title;
        }
        else{
            webTitle = i18n.global.t(router.currentRoute.value.meta.title)
        }
        
    })


}
/**
 * 是否在后台应用内
 * @param path 不传递则通过当前路由 path 检查
 */
export const isAdminApp=(path='')=>{
    if (path) {
        return /^\/admin/.test(path)
    }
    if (/^\/admin/.test(router.currentRoute.value.fullPath) || window.location.hash.indexOf('#/admin') === 0) {
        return true
    }
    return false
}